package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.JinbiOrderParentInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;


/**
 * Created by windo on 16/10/25.
 */

public class ShouYiListTask extends CouponHttpBaseTask {
    private int mSize;
    private int currentPage;

    public ShouYiListTask(int size, int pageNo) {
        super();
        mSize = size;
        currentPage = pageNo;
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject jsonObject = response.getBody();
        JinbiOrderParentInfo info = null;
        if (jsonObject != null) {
            String giftString = jsonObject.getString("data");
            info = JSON.parseObject(giftString, JinbiOrderParentInfo.class);
        }
        notifyTaskCompleted(TaskResultCode.SUCCESS, info);
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT) {
            CouponHttpRequest request = new CouponHttpRequest();
            request.setApiNo(ApiNo.TEACHERGIFTLIST);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("size", mSize);
            jsonObject.put("pageNo", currentPage);
            request.setData(jsonObject.toString());
            addRequest(request);
        }
    }
}
